import {getSubCategoryApi} from '@/apis/category.js';
import {ref,reactive,onMounted} from 'vue'



export function useSubCategory(){

  const data = reactive({
    categoryId: 1005000 ,
    page: 1,
    pageSize: 20,
    sortField: 'publishTime'
  })


  let SubCategoryList = ref([])
  const getSubCategoy = async () => {
    const res = await getSubCategoryApi(data)
    SubCategoryList.value = res.result.items
    console.log(res.result.items)
  }

  onMounted(() => {
    getSubCategoy()
  })

  let updateDate = () => {
    data.page = 1
    getSubCategoy()
    disabled.value = false
  }

  let disabled = ref(false)
  let load = async () => {
    data.page+=1
    const res = await getSubCategoryApi(data)
    SubCategoryList.value = [...SubCategoryList.value, ...res.result.items]
    if(res.result.items < 20){
      disabled.value=true
    }

  }

  return {
    SubCategoryList,
    data,
    disabled,
    updateDate,
    load
  }
}

